﻿using System;
using System.Linq;

namespace IInject.Registration.Scanning
{
	public abstract class NamingScanningRule : ScanningRule
	{
		private const string TypeNameToStringFormat = "{0}";

		protected NamingScanningRule(string prefix = "", string suffix = "")
		{
			Prefix = prefix ?? string.Empty;
			Suffix = suffix ?? string.Empty;
		}

		public override ScanningRuleType Type
		{
			get
			{
				return ScanningRuleType.Naming;
			}
		}

		public string Prefix { get; private set; }

		public string Suffix { get; private set; }

		public override string ToString()
		{
			return string.Concat(Prefix, TypeNameToStringFormat, Suffix);
		}

        public virtual string Format(Type type)
        {
            return Format(type.Name);
        }

        public virtual string Format(string typeName)
        {
            return string.Format(ToString(), typeName);
        }
	}
}
